package com.dao.imp;

import java.util.List;

import org.hibernate.Query;

import com.dao.UserinfoDao;
import com.dao.core.DaoBaseImp;
import com.page.PageDiv;
import com.pojo.Userinfo;

public class UserinfoDaoImp extends DaoBaseImp<Userinfo> implements UserinfoDao{

	@Override
	public PageDiv<Userinfo> getAllUserinfobypage(int offSet, int pageSize) {
		if(offSet>=0&&pageSize>0)
		{
			String hql="from Userinfo";
			Query q=getSession().createQuery(hql);
			q.setMaxResults(pageSize);
			q.setFirstResult(offSet);
			List<Userinfo> list=q.list();
			int totalCount=this.getCountQuery(hql);
			return new PageDiv<Userinfo>(offSet,pageSize,totalCount,list);
		}
			
		else
			return new PageDiv<Userinfo>();
	}

	@Override
	public PageDiv<Userinfo> getUserinfoBypermision(String permision,int offSet, int pageSize) {
		if(offSet>=0&&pageSize>0)
			return (PageDiv<Userinfo>) this.getAll("from Userinfo as a where a.permision=? order by a.id desc",pageSize,new Object[]{permision});
		else
			return new PageDiv<Userinfo>();
	}
	
}
